#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Last Update:

'''docstring
'''

__revision__ = '0.1'
__author__ = 'lxd'

from web import Web
import parse

PROXY_IP = ''

def test_get_local_ip_from_web():
    web = Web()
    data = web.fetch('http://www.ip138.com/ip2city.asp')
    ip = parse.get_local_ip(data)
    assert ip != None
    assert len(ip.split('.')) == 4

def test_get_proxies_from_web():
    global PROXY_IP
    web = Web()
    data = web.fetch('http://www.5uproxy.net/http_fast.html')
    proxys = parse.get_proxies(data)
    assert proxys != None
    assert(len(proxys)) != 0
    PROXY_IP = proxys[0]

def test_get_local_ip_use_proxy():
    web = Web(proxy = PROXY_IP)
    data = web.fetch('http://www.ip138.com/ip2city.asp')
    ip = parse.get_local_ip(data)
    assert ip != None
    assert len(ip.split('.')) == 4
    # 可能并不相等
    assert ip == PROXY_IP.split(':')[0]

